<?php
class stat_10
{
    function  __construct() {

    }
    function xml_online()
    {
        $query  = 'SELECT * FROM `stat__online` WHERE `time`>'.(time()-7*24*60*60).'  ORDER BY `time` ';
        $arr = _database::toarray($query);
        $xid = 0;
        $graphs = array();
        $title = array(
            1=>'запросов',
            2=>'регистраций',
            3=>'походов к друзьям',
            4=>'онлайн');
        foreach($arr as $data)
        {
            $series[$xid] = date('Y-m-d H:i',$data['time']);

            $graphs[4][$xid] = $data['online_30'];

            $xid++;
        }
        $html = '<?xml version="1.0" encoding="UTF-8"?><chart><series>';
        foreach($series as $xid => $value)
        {
            $html.='<value xid="'.$xid.'">'.$value.'</value>';
        }
        $html.='</series><graphs>';
        foreach($graphs as $gid => $data)
        {
            $html.= '<graph gid="'.$gid.'" title="'.$title[$gid].'">';
            foreach($data as $xid => $value)
            {
                $html.='<value xid="'.$xid.'">'.$value.'</value>';
            }
            $html.= '</graph>';
        }
        header ('Content-type:text/xml');
        $html.='</graphs></chart>';
        return $html;
    }


    function xml_register()
    {
        $query  = 'SELECT * FROM `stat__online` WHERE `time`>'.(time()-7*24*60*60).'  ORDER BY `time` ';
        $arr = _database::toarray($query);
        $xid = 0;
        $graphs = array();
        $title = array(
            1=>'запросов',
            2=>'регистраций',
            3=>'походов к друзьям');
        foreach($arr as $data)
        {
            $series[$xid] = date('Y-m-d H:i',$data['time']);

            $graphs[2][$xid] = $data['register_30'];

            $xid++;
        }
        $html = '<?xml version="1.0" encoding="UTF-8"?><chart><series>';
        foreach($series as $xid => $value)
        {
            $html.='<value xid="'.$xid.'">'.$value.'</value>';
        }
        $html.='</series><graphs>';
        foreach($graphs as $gid => $data)
        {
            $html.= '<graph gid="'.$gid.'" title="'.$title[$gid].'">';
            foreach($data as $xid => $value)
            {
                $html.='<value xid="'.$xid.'">'.$value.'</value>';
            }
            $html.= '</graph>';
        }
        header ('Content-type:text/xml');
        $html.='</graphs></chart>';
        return $html;
    }


    function xml_friendisit()
    {
        $query  = 'SELECT * FROM `stat__online` WHERE `time`>'.(time()-7*24*60*60).'  ORDER BY `time` ';

        $arr = _database::toarray($query);
        $xid = 0;

        $graphs = array();
        $title = array(
            1=>'запросов',
            2=>'регистраций',
            3=>'походов к друзьям');
        foreach($arr as $data)
        {
            $series[$xid] = date('Y-m-d H:i',$data['time']);

            $graphs[3][$xid] = $data['friendvisit_30'];
            $xid++;
        }



        $html = '<?xml version="1.0" encoding="UTF-8"?>
<chart>
    <series>';

        foreach($series as $xid => $value)
        {
            $html.='<value xid="'.$xid.'">'.$value.'</value>';
        }

        $html.='</series><graphs>
        ';
        foreach($graphs as $gid => $data)
        {
            $html.= '<graph gid="'.$gid.'" title="'.$title[$gid].'">';
            foreach($data as $xid => $value)
            {
                $html.='<value xid="'.$xid.'">'.$value.'</value>';
            }
            $html.= '</graph>';
        }
        header ('Content-type:text/xml');
        $html.='</graphs></chart>';
        return $html;
    }

    function xml_requests()
    {

        $query  = 'SELECT * FROM `stat__online` WHERE `time`>'.(time()-7*24*60*60).'  ORDER BY `time` ';

        $arr = _database::toarray($query);
        $xid = 0;

        $graphs = array();
        $title = array(
            1=>'запросов',
            2=>'регистраций',
            3=>'походов к друзьям');
        foreach($arr as $data)
        {
            $series[$xid] = date('Y-m-d H:i',$data['time']);
            $graphs[1][$xid] = $data['requests_30'];

            $xid++;
        }



        $html = '<?xml version="1.0" encoding="UTF-8"?>
<chart>
    <series>';

        foreach($series as $xid => $value)
        {
            $html.='<value xid="'.$xid.'">'.$value.'</value>';
        }

        $html.='</series><graphs>
        ';
        foreach($graphs as $gid => $data)
        {
            $html.= '<graph gid="'.$gid.'" title="'.$title[$gid].'">';
            foreach($data as $xid => $value)
            {
                $html.='<value xid="'.$xid.'">'.$value.'</value>';
            }
            $html.= '</graph>';
        }
        header ('Content-type:text/xml');
        $html.='</graphs></chart>';
        return $html;
    }

    function out()
    {
        if(isset($_GET['xml']))
        {
            ob_end_clean();
            if($_GET['xml'] == 'register') return $this->xml_register();
            if($_GET['xml'] == 'requests') return $this->xml_requests();
            if($_GET['xml'] == 'friendisit') return $this->xml_friendisit();
            if($_GET['xml'] == 'online') return $this->xml_online();
        }
        $html = '
<div id="flashcontent4"></div>
<div id="flashcontent1"></div>
<div id="flashcontent2"></div>
<div id="flashcontent3"></div>
<script type="text/javascript">
        var so = new SWFObject("/admin/js/amline/amline.swf", "amline", "620", "400", "8", "#FFFFFF");
        so.addVariable("path", "/admin/js/amline/");
        so.addVariable("settings_file", encodeURIComponent("/admin/js/amline/amline_settings.xml"));
        so.addVariable("data_file", encodeURIComponent("http://world.ljrate.ru/admin/?page=10&xml=register"));
        so.write("flashcontent1");
</script>
<script type="text/javascript">
        var so = new SWFObject("/admin/js/amline/amline.swf", "amline", "620", "400", "8", "#FFFFFF");
        so.addVariable("path", "/admin/js/amline/");
        so.addVariable("settings_file", encodeURIComponent("/admin/js/amline/amline_settings.xml"));
        so.addVariable("data_file", encodeURIComponent("http://world.ljrate.ru/admin/?page=10&xml=requests"));
        so.write("flashcontent2");
</script>
<script type="text/javascript">
        var so = new SWFObject("/admin/js/amline/amline.swf", "amline", "620", "400", "8", "#FFFFFF");
        so.addVariable("path", "/admin/js/amline/");
        so.addVariable("settings_file", encodeURIComponent("/admin/js/amline/amline_settings.xml"));
        so.addVariable("data_file", encodeURIComponent("http://world.ljrate.ru/admin/?page=10&xml=friendisit"));
        so.write("flashcontent3");
</script>
<script type="text/javascript">
        var so = new SWFObject("/admin/js/amline/amline.swf", "amline", "620", "400", "8", "#FFFFFF");
        so.addVariable("path", "/admin/js/amline/");
        so.addVariable("settings_file", encodeURIComponent("/admin/js/amline/amline_settings.xml"));
        so.addVariable("data_file", encodeURIComponent("http://world.ljrate.ru/admin/?page=10&xml=online"));
        so.write("flashcontent4");
</script>

';
        return $html;
    }
}
?>
